package states;

import hypeerweb.Range;

/**
 * The larger node class from which all other state classes extend.
 *
 * @author brinkerhoff_kendra
 *
 */
public abstract class NodeState {

	/**
	 * The range in which we will find the insertion node.
	 */
	protected Range range;

	/**
	 * The state_id that refers to the current state of the node.
	 */
	public static int STATE_ID = 4;

	/**
	 * Shrinks the given range according to the state of the machine. To goal of is to
	 * create a range where lowerBound.parent.webid + 1 == upperBound.webid
	 *
	 * @param r the range in which we will find the insertion node and deletion node.
	 */
	public abstract NodeState shrinkRange(final Range r);

	/**
	 * Gives the node state that corresponds to the given id.
	 *
	 * @param id the STATE_ID of a node state
	 * @return the corresponding state
	 */
	public static NodeState getNodeState(final int id) {
		if (id == 0) {
			return new StandardNodeState();
		}
		else if(id == 1) {
			return new UpPointingNodeState();
		}
		else if(id == 2) {
			return new DownPointingNodeState();
		}
		else if(id == 3) {
			return new HypercubeCapNodeState();
		}
		else {
			return new TerminalNodeState();
		}
	}
}
